package cn.g31010.sip.model
{
	import cn.g31010.sip.vo.User;
	
	import com.adobe.cairngorm.model.ModelLocator;
	
	import mx.collections.ArrayCollection;
	
	public class UserModel implements ModelLocator
	{
		private static var modelLocator : UserModel;
		public static function getInstance() : UserModel 
		{
			if ( modelLocator == null ){
				modelLocator = new UserModel();
			}
			return modelLocator;
	   }
	   
   		public function UserModel() 
   		{
   			if ( UserModel.modelLocator != null )
				throw new Error( "Only one ModelLocator instance should be instantiated" );	
			
   		}
   		
   		[Bindable]
   		public var currentUser:User;
   		
   		[Bindable]
   		public var users:ArrayCollection=new ArrayCollection();
   		
   		[Bindable]
   		public var privateUsers:ArrayCollection=new ArrayCollection();
   		
   		public function addPrivateUser(u:User):void{
   			privateUsers.addItem(u);
   		}
   		public function removePrivateUser(id:String):User{
   			for(var i:int=0;i<privateUsers.length;i++){
   				if(privateUsers[i].id==id){
   					return privateUsers.removeItemAt(i) as User;
   				}
   			}
   			return null;
   		}
   		public function removeUser(id:String):User{
   			for(var i:int=0;i<users.length;i++){
   				if(users[i].id==id){
   					return users.removeItemAt(i) as User;
   				}
   			}
   			return null;
   		}
   		
   		public function addUser(u:User):void{
   			users.addItem(u);
   		}
   		
	}
}